#ifndef	__BFX_REF_XMLATTRIBUTE_H__
#define	__BFX_REF_XMLATTRIBUTE_H__

namespace BFX
{

//////////////////////////////////////////////////////////////////////////////

// Represents an attribute of the XMLElement object. Valid and default values for the attribute are defined in a DTD or schema.
class BFX_API REFXMLAttribute : public REFXMLNode
{
	friend class REFXMLDocument;
	friend class REFXMLAttributeMap;

protected:
	REFXMLAttribute(REFXMLName* pName, REFXMLDocument* pDoc);
	REFXMLAttribute(const UniString& strPrefix, const UniString& strLocalName, const UniString& strNamespaceURI, REFXMLDocument* pDoc);
public:
	virtual ~REFXMLAttribute();

	// Gets the parent of this node (for nodes that can have parents).
    virtual REFXMLNode* GetParentNode() const;
	// Gets the name of the node.
	virtual UniString GetName() const;
	// Gets the name of the node without the namespace prefix.
	virtual UniString GetLocalName() const;
	// Gets the namespace URI of this node.
	virtual UniString GetNamespaceURI() const;
	// Gets or sets the namespace prefix of this node.
	virtual UniString GetPrefix() const;
	virtual void SetPrefix(const UniString& str);

	// Gets the type of the current node.
	virtual XMLNodeType GetNodeType() const;

	// Gets the XmlDocument that contains this node.
	virtual REFXMLDocument* GetOwnerDocument() const;

	// Gets or sets the value of the node.
	virtual UniString GetValue() const;
	virtual void SetValue(const UniString& str);

	virtual void SetInnerText(const UniString& str);

	// DOM Level 2

	// Gets the XmlElement node that contains this attribute.
	virtual REFXMLElement* GetOwnerElement() const;
	// Gets or sets the markup representing just the children of this node.
	virtual void SetInnerXml(const UniString& str);


	// Saves the current node to the specified XmlWriter.
	virtual void WriteTo(REFXMLWriter* w) const;
	// Saves all the children of the node to the specified XmlWriter.
	virtual  void WriteContentTo(REFXMLWriter* w) const;

protected:
	virtual void SetParent(REFXMLNode* pNode);
	
	virtual bool IsContainer() const;
	virtual REFXMLLinkedNode* GetFirstNode() const;
	virtual void SetFirstNode(REFXMLLinkedNode* pNode);
	virtual REFXMLLinkedNode* GetLastNode() const;
	virtual void SetLastNode(REFXMLLinkedNode* pNode);
	
	virtual bool IsValidChildType(XMLNodeType type) const;

	bool PrepareOwnerElementInElementIdAttrMap();
	void ResetOwnerElementInElementIdAttrMap(const UniString& strOldInnerText);

	REFXMLName* GetXmlName() const;
	void SetXmlName(REFXMLName* pName);

protected:
	REFXMLName*	m_pName;
	REF<REFXMLLinkedNode>	m_pFirstChild;
	REFXMLLinkedNode*	m_pLastChild;
};

//////////////////////////////////////////////////////////////////////////////

// Represents an unspecified attribute of the XMLElement object.
class REFXMLUnspecifiedAttribute : public REFXMLAttribute
{
	friend class REFXMLDocument;
protected:
	REFXMLUnspecifiedAttribute(const UniString& strPrefix, const UniString& strLocalName, const UniString& strNamespaceURI, REFXMLDocument* pDoc);
public:
	virtual ~REFXMLUnspecifiedAttribute();

	// Sets the concatenated values of the node and all its children.
	virtual void SetInnerText(const UniString& str);

	// Inserts the specified node immediately before the specified reference node.
	virtual REFXMLNode* InsertBefore(REFXMLNode* pNewChild, const REFXMLNode* pRefChild);
	// Inserts the specified node immediately after the specified reference node.
	virtual REFXMLNode* InsertAfter(REFXMLNode* pNewChild, const REFXMLNode* pRefChild);

	// Replaces the child node oldChild with newChild node.
	virtual REFXMLNode* ReplaceChild(REFXMLNode* pNewChild, REFXMLNode* pOldChild);
	// Removes specified child node.
	virtual REFXMLNode* RemoveChild(REFXMLNode* pOldChild);
	// Adds the specified node to the end of the list of children of this node.
	virtual REFXMLNode* AppendChild(REFXMLNode* pNewChild);

	// Saves the current node to the specified XmlWriter.
	virtual void WriteTo(REFXMLWriter* w) const;

	bool IsSpecified() const;

protected:
	void SetSpecified(bool bSpecified);

protected:
	bool	m_bSpecified;
};

}	//	namespace BFX

#endif	//	__BFX_REF_XMLATTRIBUTE_H__
